import { InjectionKey } from 'vue';
import { createStore, Store, useStore } from 'vuex';
// import { getStorage, saveStorage } from '@/utils/local-storage';

/**
 * 基础Store属性
 */
export interface State {
    /** 条码号列表 */
    gdBarcodeList: Array<Record<string, any>>;
    lsBarcodeList: Array<Record<string, any>>;
}

export const key: InjectionKey<Store<State>> = Symbol();

/**
 * 基础Store
 */
export const store = createStore<State>({
    state: {
        gdBarcodeList: [],
        lsBarcodeList: [],
    },
    // TODO: TS支持
    mutations: {
        SET_STATE(state: any, params) {
            // 进度条单独处理重新置0
            state[params.name] = params.value;
        },
    },
});

/**
 * 基础Store
 */
export function useBaseStore(): Store<State> {
    return useStore(key);
}
